package com.atguigu.gmall.seckill.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.seckill.SeckillApplication;
import com.atguigu.gmall.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 秒杀的控制层
 */
@RestController
@RequestMapping(value = "/seckill/goods")
public class SeckillGoodsController {
    @Autowired
    private SeckillService seckillService;

    /**
     * 查询商品列表
     * @param time
     * @return
     */
    @GetMapping(value = "/list/{time}")
    public Result getGoodsList(@PathVariable(value = "time") String time){
        List<SeckillGoods> seckillGoods = seckillService.getSeckillGoods(time);
        return  Result.ok(seckillGoods);
    }

    /**
     * 查询商品列表
     * @param time
     * @param id
     * @return
     */
    @GetMapping(value = "/one/{time}/{id}")
    public  Result getGoods(@PathVariable(value = "time") String time,
                            @PathVariable(value = "id") String id){
        SeckillGoods seckillGood = seckillService.getSeckillGood(time, id);
        return  Result.ok(seckillGood);
    }

}
